home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
yoonoGlobMemo.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
8KB
|
232 lines
// 2007 Xavier Grosjean
// Methods for Memo
// These are markers used to delimit the selection during processing. They
// are removed from the final rendering, but we pick space-like characters for
// safety (and futhermore, these are known to be mapped to a 0-length string
// in transliterate.properties). It is okay to set start=end, we use findNext()
// U+200B ZERO WIDTH SPACE
const MARK_SELECTION_START = '\u200B\u200B\u200B\u200B\u200B';
const MARK_SELECTION_END = '\u200B\u200B\u200B\u200B\u200B';
yoonoGlob.previousSelectedText = '';
// Wrapper method called when a create memo button is clicked
// checks if user is not anonymous
yoonoGlob.createMemo = function(parentId) {
var folderMsg = '';
if(parentId) folderMsg = ' in folder ' + parentId;
YOONO_LOG.debug('Creating new Memo' + folderMsg);
try {
var userId = YNPREFBRANCH.getCharPref("userid");
if(!userId.match(':')) {
alert("Anonymous users can't create Memos");
return;
}
alert("TODO : yoonoGlob.createMemo");
} catch(e) {
YOONO_LOG.exception(e);
}
}
// Wrapper method called when a create memo folder button is clicked
// checks if user is not anonymous
yoonoGlob.createFolder = function(parentId) {
var folderMsg = '';
if(parentId) folderMsg = ' in folder ' + parentId;
YOONO_LOG.debug('Creating new Folder' + folderMsg);
try {
var userId = YNPREFBRANCH.getCharPref("userid");
if(!userId.match(':')) {
alert("Anonymous users can't create Memos");
return;
}
alert("TODO : yoonoGlob.createFolder");
} catch(e) {
YOONO_LOG.exception(e);
}
}
// Fills the document context menu and auto menu submenu with all available memos
yoonoGlob.showMemoContextMenu = function(evt, popup) {
// this proc gets called for each submenu showing...
if('mainPopup' != evt.target.getAttribute('name')) {
return;
}
YOONO_LOG.debug('MENU');
// Empty menu first
while(popup.firstChild) {
popup.removeChild(popup.firstChild);
}
var title = '';
var memo = null;
var menuitem = null;
// Fill the popup
createRecursiveContextMemoMenu(popup, 0);
function createRecursiveContextMemoMenu(popup, memoParentId) {
var submenu = null;
var menuitem = null;
var memo = null;
var id = null;
var title = '';
for(var i=0 ; i<yoonoGlob.MemoMgr._memoList.length; i++) {
memo = yoonoGlob.MemoMgr._memoList[i];
if(memo.parentId != memoParentId) continue;
if('share' == memo.shortcutType) continue;
title = memo.title;
switch(memo.type) {
case 'MEMO':
menuitem = document.createElement('menuitem');
menuitem.setAttribute('label', title);
menuitem.setAttribute('oncommand', 'YOONO_CMPT.addStat(["buzz", "context-menu"]);yoonoGlob.addSelectionToMemo("' + memo.id + '")');
popup.appendChild(menuitem);
break;
case 'FOLDER':
submenu = document.createElement('menu');
submenu.setAttribute('label', title);
//id = memo.buttonIdFromFeedId();
submenu.setAttribute('id', memo.id);
submenu.setAttribute('class', 'menu-iconic contextmemofoldermenu');
var subpopup = document.createElement('menupopup');
submenu.appendChild(subpopup);
// insert on top of menu
if(!popup.firstChild) {
popup.appendChild(submenu);
} else {
popup.insertBefore(submenu, popup.firstChild);
}
createRecursiveContextMemoMenu(subpopup, memo.id);
// insert a 'create memo' menuitem on top of this submenu
// addCreateMemoMenuItem(subpopup, memo.id);
break;
}
}
}
function addCreateMemoMenuItem(popup, memoId) {
var menuItem = document.createElement('menuitem');
var label = yoonoGlob.gStrbundle.getString('memo.create.infolder');
if(popup.getAttribute('name') == 'mainPopup')
label = yoonoGlob.gStrbundle.getString('memo.create');
menuItem.setAttribute('label', label);
menuItem.setAttribute('oncommand', 'yoonoGlob.createMemo(' + memoId + ')');
var sep = document.createElement('menuseparator');
// if popup is empty, append
if(!popup.firstChild)
popup.appendChild(sep);
else
popup.insertBefore(sep, popup.firstChild);
popup.insertBefore(menuItem, popup.firstChild);
}
}
yoonoGlob.addSelectionToMemo = function(idMemo) {
YOONO_LOG.debug('yoonoGlob.addSelectionToMemo : ' + idMemo);
var text = yoonoGlob.getSelectedText();
if(yoonoGlob.sidebar.visible) {
var result = yoonoGlob.sidebar.sidebarMethods.methods.addToMemo(idMemo, text);
} else {
yoonoGlob.toggleSb();
// HAHA just for fun. Make it better asap
setTimeout(function() {
yoonoGlob.sidebar.sidebarMethods.methods.addToMemo(idMemo, text);
}, 1000);
}
}
yoonoGlob.hideMemoContextMenu = function(popup) {
}
yoonoGlob.getSelectedText = function() {
var morceau = '';
try {
if(gContextMenu && !gContextMenu.isTextSelected) {
if(gContextMenu.imageURL) {
var b = getBrowser();
var urlPage = b.contentDocument.URL;
morceau = '<img src="' + gContextMenu.imageURL + '" '
+ 'class="yoono-image" onclick="window.open(\''
+ urlPage + '\', \'\')" link="true">';
return(morceau);
}
if(gContextMenu.link) {
morceau = '<a href="' + gContextMenu.link + '" '
+ 'target="_blank">' + gContextMenu.link + '</a>';
return(morceau);
}
}
var fwsel = yoonoGlob.getSelection();
if(!fwsel) {
return '';
}
var sel= fwsel[1];
if(sel && sel.isCollapsed) return '';
var fw = fwsel[0];
var doc = fw.document;
// Dé relativiser les images
var img = null;
for(var i=0 ; i < doc.images.length; i++) {
img = doc.images[i];
img.setAttribute('src', img.src);
}
// dé relativiser les links
var link = null;
for(var i=0 ; i < doc.links.length; i++) {
link = doc.links[i];
link.setAttribute('href', link.href);
}
// texte sans html : sel.toString();
var content = YOONO_SIDEBAR.getContainerForSelection(sel);
var xhtml = YOONO_SIDEBAR.serializer.serializeToString(content);
morceau = xhtml.slice(xhtml.indexOf(MARK_SELECTION_START) + MARK_SELECTION_START.length, xhtml.lastIndexOf(MARK_SELECTION_END));
var cleanDiv = doc.createElement('div');
// We need to remove all 'on...' attributes that could be used to execute malicious code...
// and remove the scripts too
cleanDiv.innerHTML = morceau;
var tags = cleanDiv.getElementsByTagName('*');
var elt = null;
var attr = null;
var nbAttr = 0;
for(var i=0 ; i < tags.length; i++) {
var elt = tags[i];
if('SCRIPT' == elt.nodeName) {
elt.innerHTML = '';
}
if(('attributes' in elt) && elt.attributes.length) {
nbAttr = elt.attributes.length;
for(var j=nbAttr - 1 ; j >= 0; j--) {
attr = elt.attributes[j];
if('on' == attr.name.substr(0,2)) {
elt.removeAttribute(attr.name);
}
}
}
}
morceau = cleanDiv.innerHTML;
} catch(e) {
YOONO_LOG.exception(e);
}
return(morceau);
}
yoonoGlob.getSelection = function() {
var focusedWindow = yoonoGlob.focusedWindow;
if (!focusedWindow || !focusedWindow.document)
return null;
var selection = focusedWindow.getSelection();
return([focusedWindow, selection]);
}